define(function(require, exports, module) {

    var $ = require('$'),
        _ = require('underscore'),
        Backbone = require('backbone'),
        PlanModel = require('model/plan'),
        PlanCollection = require('collection/plan');

    //接收options = {gomac: app, objectId: }
    module.exports = Backbone.View.extend({
        el: '.page[data-page=planView]',
        events: {
        },
        template: require('tpl/plan/view.handlebars'),
        initialize: function(options) {
            var self = this;
            
            //传入gomac
            this.gomac = options.gomac;

            //新建模型
            this.model = new PlanModel;
            //设置collection
            this.model.collection = new PlanCollection;
            //设置id
            this.model.id = options.objectId;
            //本地获取
            this.model.fetch({
                success: function(model, response, options) {
                    //获取成功
                    self.model.time.id = model.get('time');
                    self.model.time.fetch({
                        success: function(time, resp, opt) {
                            self.$el.find('.page-content').html(self.template({
                                model: self.model.toJSON(),
                                time: time.showData()
                            }));
                        },
                        error: function(time, resp, opt) {
                            console.log('获取时间出错',time,resp,opt);
                        }
                    });
                },
                error: function(model, response, options) {
                    console.log('获取安排出错',model,response,options);
                }
            });
        }
    });
});